package edu.uj.petri.document;

import edu.uj.petri.gui.MainWindowInterface;
import edu.uj.petri.model.Marking;

/**
 * document mode in simulation
 * @author Piotrek
 */
class SimulationMode extends ConcreteMode {
    
    private Marking marking;
    
    public SimulationMode() {
    }

    /**
     * disables design buttons, enables simulation buttons, clears element 
     *    selection, remembers initial marking
     */
    public void applyTo(MainWindowInterface window, Document document) {
        window.setDesignButtonsEnabled(false);
        window.setSimulationButtonsEnabled(true);
        window.setCommandStack(commandStack);
        marking = document.getModel().getMarking();
        document.getView().selectNone();
        document.getSimulation().applyTo(window);
        document.getSimulation().showAllActiveTransitions();
    }

    /**
     * this method is called when this document mode is switched away and
     * another mode is set instead
     */
    public void finish(MainWindowInterface window, Document document) {
        document.getModel().applyMarking(marking);
        commandStack.clear();
        document.getSimulation().reset();
        document.getSimulation().finish();
    }
    
}
